package com.atguigu.srb.core.util;

import com.atguigu.srb.core.enums.ReturnMethodEnum;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Bright
 * @Date: 2022-04-28 10:11
 * @Description: 根据还款方式计算
 * @version: 1.0
 */
public class AmountHelper {


    /**
     * 等额本金计算每月本息
     * @param invest 总借款额（贷款本金）
     * @param yearRate 年利率
     * @param totalMonth 还款总月数
     * @return 每月偿还利息
     */
    public static Map<Integer, BigDecimal> getPerMonthPrincipalInterest(BigDecimal invest, BigDecimal yearRate, int totalMonth) {

                return Amount2Helper.getPerMonthPrincipalInterest(invest,yearRate,totalMonth);


    }


    /**
     * 计算每月还款利息
     * @param invest
     * @param yearRate
     * @param totalMonth
     * @return
     */
    public static Map<Integer, BigDecimal> getPerMonthInterest(BigDecimal invest, BigDecimal yearRate, int totalMonth,int returnMethod){

        if (returnMethod == ReturnMethodEnum.ONE.getMethod()) {
            return Amount1Helper.getPerMonthInterest(invest, yearRate, totalMonth);
        } else if (returnMethod == ReturnMethodEnum.TWO.getMethod()) {
            return Amount2Helper.getPerMonthInterest(invest, yearRate, totalMonth);
        } else if (returnMethod == ReturnMethodEnum.THREE.getMethod()) {
            return Amount3Helper.getPerMonthInterest(invest, yearRate, totalMonth);
        } else if (returnMethod == ReturnMethodEnum.FOUR.getMethod()) {
            return Amount4Helper.getPerMonthInterest(invest, yearRate, totalMonth);
        }
        return new HashMap<>(0);

    }



    /**
     * 每月还款本金
     * @param invest 总借款额（贷款本金）
     * @param yearRate 年利率
     * @param totalMonth 还款总月数
     * @return 每月偿还本金
     */
    public static Map<Integer, BigDecimal> getPerMonthPrincipal(BigDecimal invest, BigDecimal yearRate, int totalMonth,int returnMethod) {

        if (returnMethod == ReturnMethodEnum.ONE.getMethod()) {
            return Amount1Helper.getPerMonthPrincipal(invest, yearRate, totalMonth);
        } else if (returnMethod == ReturnMethodEnum.TWO.getMethod()) {
            return Amount2Helper.getPerMonthPrincipal(invest, yearRate, totalMonth);
        } else if (returnMethod == ReturnMethodEnum.THREE.getMethod()) {
            return Amount3Helper.getPerMonthPrincipal(invest, yearRate, totalMonth);
        } else if (returnMethod == ReturnMethodEnum.FOUR.getMethod()) {
            return Amount4Helper.getPerMonthPrincipal(invest, yearRate, totalMonth);
        }
        return new HashMap<>(0);
    }


    /**
     * 总利息
     * @param invest
     * @param yearRate
     * @param totalMonth
     * @return
     */
    public static BigDecimal getInterestCount(BigDecimal invest, BigDecimal yearRate, int totalMonth,int returnMethod) {

        if (returnMethod == ReturnMethodEnum.ONE.getMethod()) {
            return Amount1Helper.getInterestCount(invest, yearRate, totalMonth);
        } else if (returnMethod == ReturnMethodEnum.TWO.getMethod()) {
            return Amount2Helper.getInterestCount(invest, yearRate, totalMonth);
        } else if (returnMethod == ReturnMethodEnum.THREE.getMethod()) {
            return Amount3Helper.getInterestCount(invest, yearRate, totalMonth);
        } else if (returnMethod == ReturnMethodEnum.FOUR.getMethod()) {
            return Amount4Helper.getInterestCount(invest, yearRate, totalMonth);
        }
        return new BigDecimal(0);
    }

}
